package piblanes;

import java.awt.*;
import java.awt.geom.Point2D;
import java.util.*;
import piblanes.apache.Polygon2D;

/**
 * 
 */
public class Player {
    void receiveSignal(ControllerSignal signal) {
        if (actions.size() >= queueSize)
            actions.removeLast();

        actions.addLast(signal);
    }

    Player (Point2D coordinates_, double direction_, Polygon2D shape_) {
        geometricalState = new PlayerGeometricalState(coordinates_, direction_, shape_);
    }

    public boolean hasAction() {
        return !actions.isEmpty();
    }

    // Simple constructor. Biplane will start at (0,0) and have rectangle shape
    Player () {
        actions = new ArrayDeque<ControllerSignal>(queueSize);

        int[] xpoints = {-2,2,2,-2};
        int[] ypoints = {-1,-1,1,1};

        geometricalState = new PlayerGeometricalState(new Point2D.Double(5,5), Math.PI/3, new Polygon2D(xpoints, ypoints, 4));
    }

    void move(double shiftX, double shiftY) {
        geometricalState.move(shiftX, shiftY);
    }

    void move(Point2D shift) {
        geometricalState.move(shift);
    }

    public void removeFirstAction() {
        if (!actions.isEmpty()) {
            actions.removeFirst();
        }
    }
    
    public ControllerSignal getFirstAction() {
        return actions.getFirst();
    }

    public double getVelocity() {
        return velocity;
    }

    public void setVelocity(double velocity) {
        this.velocity = velocity;
    }

    public GeometricalState getGeometricalState() {
        return geometricalState;
    }

    public static final int queueSize = 100;
    private ArrayDeque<ControllerSignal> actions;
    private PlayerGeometricalState geometricalState;
    private double velocity = 1;
    private double velocityLimit = 1;
}
